<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2023 yoncron All rights reserved.
// +----------------------------------------------------------------------
// | Author: yoncron <yoncron@163.com>
// +----------------------------------------------------------------------
namespace app\model\view;
use think\facade\Db;

class NearbyUserView
{
    public function lst($app_id=0,$user_id=0,$lon='',$lat='',$page=1,$limit=20){
        $page = $page - 1;
        $sql = "
        select user_id,username,avatar,sex,FORMAT((ACOS(SIN(( {$lat} * 3.1415) / 180 ) *SIN((latitude * 3.1415) / 180 ) +COS(( {$lat} * 3.1415) / 180 ) * COS((latitude * 3.1415) / 180 ) *COS(( {$lon} * 3.1415) / 180 - (longitude * 3.1415) / 180 ) ) * 6380),3) AS 'distance',online_status from base_user
        where latitude IS NOT NULL AND longitude IS NOT NULL AND user_id != 10000 AND useable=1 AND deleted=0 AND user_id != {$user_id} AND app_id={$app_id}
        order by distance asc
        limit {$page},{$limit}
        ";
        $res = Db::query($sql);
        return $res;
    }
}